<?php
/**
 * Achievements for BuddyPress. This file ensures that BuddyPress is loaded first.
 *
 * @author Paul Gibbs <paul@byotos.com>
 * @package Achievements for BuddyPress
 *
 * $Id: achievements.php 956 2011-03-02 09:57:12Z DJPaul $
 */

/*
Plugin Name: Achievements
Plugin URI: http://achievementsapp.com/
Description: Achievements gives your BuddyPress community fresh impetus by promoting and rewarding social interaction with challenges, badges and points.
Version: 2.1
Requires at least: WP 3.1, BuddyPress 1.2.8
Tested up to: WP 3.1, BuddyPress 1.2.8
License: General Public License version 2
Author: Paul Gibbs
Author URI: http://byotos.com/
Network: true
Domain Path: /includes/languages/
Text Domain: dpa

"Achievements for BuddyPress"
Copyright (C) 2009-11 Paul Gibbs

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see http://www.gnu.org/licenses/.
*/

define ( 'ACHIEVEMENTS_DB_VERSION', 29 );

/**
 * Only load the component if BuddyPress is loaded and initialised. 
 *
 * @since 2.0
 */
function dpa_include() {
	dpa_check_upgrades();
	require( dirname( __FILE__ ) . '/includes/achievements-loader.php' );

	do_action( 'dpa_include' );
}
add_action( 'bp_include', 'dpa_include' );

/**
 * Manages plugin install and upgrade.
 *
 * @since 2.1
 * @global object $bp BuddyPress global settings
 * @global wpdb $wpdb WordPress database object
 */
function dpa_check_upgrades() {
	global $bp, $wpdb;

	$version = get_site_option( 'achievements-db-version' );
	if ( false !== $version && ACHIEVEMENTS_DB_VERSION == $version )
		return;

	if ( empty( $version ) )
		$version = 0;

	if ( $version != ACHIEVEMENTS_DB_VERSION ) {
		if ( $version > 0 && $version <= 27 ) {  // CPT introduced in v2.1
			add_action( 'init', 'dpa_upgrade_to_cpt' );
			$version = 28;
		}

		for ( $i=$version; $i<ACHIEVEMENTS_DB_VERSION; $i++ ) {
			switch ( $i ) {
				case 0;
					add_action( 'init', 'dpa_install' );
				break;

				case 28:
				break;
			}
		}

		update_site_option( 'achievements-db-version', ACHIEVEMENTS_DB_VERSION );
	}
}
?>